﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using PPI.Data.Inspection;
using PPI.Entities.Interface;
using PPI.Mobile;
using VMind.Global;

namespace PPI.ServiceLogic.Inspections
{
    public class LMap : IMobileTable
    {
        public static DataSet SelectAll(string connectionKey)
        {
            return DInspectionMap.SelectAll(connectionKey);
        }


        public List<EMobileQuery> CreateInsertMobileQuery(string connectionKey)
        {
            List<EMobileQuery> listQueries = new List<EMobileQuery>();
            StringBuilder _Sql = new StringBuilder();
            DataTable _Dt = SelectAll(connectionKey).Tables[0];

            listQueries.Add(new EMobileQuery("Delete tb_Sections"));
            listQueries.Add(new EMobileQuery("Delete tb_Maps"));
            foreach (DataRow dr in _Dt.Rows)
            {
                if (ConvertHelper.ToInt32(dr["PolygonParentId"]) == Int32.MinValue)
                    listQueries.Add(new EMobileQuery("insert into tb_Maps (MapId, Name) values (" + ConvertHelper.ToInt32(dr["PolygonChildId"]) + ",'" + dr["PolygonChildName"].ToString() + "')"));
            }

            foreach (DataRow dr in _Dt.Rows)
            {
                if (ConvertHelper.ToInt32(dr["PolygonParentId"]) != Int32.MinValue)
                    listQueries.Add(new EMobileQuery("insert into tb_Sections (SectionId, MapFk,Name) values (" + ConvertHelper.ToInt32(dr["PolygonChildId"]) + "," + ConvertHelper.ToInt32(dr["PolygonParentId"]) + ",'" + dr["PolygonChildName"].ToString() + "')"));
            }


            return listQueries;
        }
    }
}
